package com.hong.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hong.bean.User;
import com.hong.dao.UserMapper;
import com.hong.dto.QueryUserDTO;
import com.hong.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.Collections;
import java.util.List;
import java.util.Objects;


@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public List<User> getList(QueryUserDTO param) {
        List<User> users = lambdaQuery()
                .eq(StringUtils.hasText(param.getUsername()), User::getUsername, param.getUsername())
                .eq(Objects.nonNull(param.getSex()), User::getSex, param.getSex())
                .eq(Objects.nonNull(param.getAddressId()), User::getAddressId, param.getAddressId()).list();
        if (CollectionUtils.isEmpty(users)){
            return Collections.EMPTY_LIST;
        }
        return users;
    }
}
